<template>
	<view class="page">
		<view class="user-info">
			<view class="info-item">
				<view class="photo">
					<image src="../../../../static/dafaulthead2.png" v-if="detail.avatarUrl == ''"></image>
					<image :src="detail.avatarUrl" mode="aspectFill" v-else></image>
				</view>
				<view class="info-box">
					<view class="info msg">
						<view class="name">{{ detail.nickName }}</view>
						<image class="crown" src="../../../../static/vip1.png"></image>
					</view>
					<text>{{vip_time}}到期</text>
				</view>
			</view>
		</view>

		<view class="combo">
			<text class="combo-title">会员套餐</text>
			<view class="combo-content">
				<view class="combo-item" v-for="(item,index) of selectType" @click="doSelectType(item)" :class="type == index ? 'have' : ''">
					<text class="combo-item-name">{{item.name}}</text>
					<text class="combo-item-price">&yen{{item.price}}</text>
					<text class="combo-item-originalPrice">{{item.originalPrice}}</text>
				</view>
			</view>
		</view>
		<view class="privilege combo">
			<text class="combo-title privilege-title">会员特权</text>
			<view class="privilege-item">
				<view class="privilege-content">
					<image src="../../../../static/order30.png"></image>
				</view>
				<text class="describe">增加30次接单</text>
			</view>
			<view class="privilege-item">
				<view class="privilege-content">
					<image src="../../../../static/exalted.png"></image>
				</view>
				<text class="describe">尊贵会员标识</text>
			</view>
		</view>
		<view class="dredge">
			<view class="line"></view>
			<view class="dredge-item">
				<view class="dredge-content">
					<text class="combo-item-name dredge-name">{{renewName}}</text>
					<text class="combo-item-price dredge-price">&yen {{renewPrice}}</text>
				</view>
				<!-- <view class="dredge-btn" @click="renewVIp">会员续费</view> -->
			</view>
		</view>
		<view class="developing" v-if="developing">
			正在开发当中，请尽情期待... ...
		</view>
		<!-- 没有记录 -->
		<!-- <view class=" d-c-c p30" v-if="vipType.length == 0">				
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<uni-load-more v-else :loadingType="loadingType"></uni-load-more> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				developing: true,
				vipType:'',
				detail: {
					avatarUrl: '', //头像
				},
				vip_time: '2023-2-2',
				/* 会员到期时间 */
				type: 0,
				selectType: [{
						name: '月度会员',
						price: '98',
						originalPrice: '原价100元',
						id: 0
					},
					{
						name: '季度会员',
						price: '168',
						originalPrice: '原价258元',
						id: 1
					},
					{
						name: '年度会员',
						price: '360',
						originalPrice: '原价460元',
						id: 2
					},
					{
						name: '终身会员',
						price: '888',
						originalPrice: '原价998元',
						id: 3
					}
				],
				renewPrice: '98',
				renewName:'月度会员'
			};
		},
		onShow() {
			this.getVipinfo();
			this.getDatainfo();
		},
		methods: {
			renewVIp() {
				let self = this;
				let formdata = {};
				
				formdata.renewVipName = self.selectType[self.type].name;
				formdata.renewVipPrice = self.selectType[self.type].price;
				formdata.renewVipId = self.selectType[self.type].id;
				console.log(formdata);
				uni.showLoading({
					title: '正在续费'
				});
				self._post(
					'user.index/vip',
					formdata,
					// result:() =>{
						
					// }
					result => {
						// 记录token user_id
						// uni.setStorageSync('token', result.data.token);
						// uni.setStorageSync( 'user_id', result.data.user_id );
						// uni.requestPayment({
						// 	provider:'alipay',
						// 	orderInfo:'orderInfo'
						// });
						// if (result.code == 1) {
						// 	uni.showToast({
						// 		title: '续费成功！',
						// 		duration: 2000,
						// 		icon: 'none'
						// 	});
						// 	self.gotoPage('/pages/user/renew/renew');
						// }
						// 执行回调函数
						// uni.navigateBack();
					},

					false,
					() => {
						uni.hideLoading();
					}
				);
			},
			doSelectType: function(item) {
				let self = this;
				self.type = item.id;
				self.renewPrice = self.selectType[self.type].price;
				self.renewName = self.selectType[self.type].name;
			},
			/*获取个人数据*/
			getDatainfo() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('user.index/detail', {}, function(res) {

					self.detail = res.data.userInfo;
					self.detail.avatarUrl = res.data.userInfo.avatarUrl,
						self.loadding = false;
				});
			},
			/*获取会员数据*/
			getVipinfo() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('user.index/vip', {}, function(res) {
					console.log(res);
					self.vipType = res.data.vip;
					self.loadding = false;
				});
			},
		}
	}
</script>

<style lang="scss">
	@import 'renew.scss';
</style>
